package control.options;

import device.IXmlConfig;
import environment.data.BaseEnvironmentData;
import org.w3c.dom.Element;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Created by vondoom on 04.06.2014.
 */
public class RoomConfig implements IConfigObject, IXmlConfig {

    private String idXml;
    private Long minTemperature;
    private Long maxTemperature;
    private Map<BaseEnvironmentData.EnvironmentData,List<Long>> mapConfig;

    public RoomConfig(String idXml){
        this.idXml = idXml;
        mapConfig = new ConcurrentHashMap<BaseEnvironmentData.EnvironmentData, List<Long>>();
    }

    @Override
    public String getIdFromXml() {
        return idXml;
    }

    @Override
    public void initFromXml(Element element) {
        this.minTemperature  = Long.parseLong(element.getElementsByTagName("minTemperature").item(0).getChildNodes().item(0).getNodeValue());
        this.maxTemperature  = Long.parseLong(element.getElementsByTagName("maxTemperature").item(0).getChildNodes().item(0).getNodeValue());
        System.out.println(/*this.getName()+ */" min: " + minTemperature);
        System.out.println(/*this.getName()+*/" max: " + maxTemperature);

        List<Long> temperatureConfigList = new CopyOnWriteArrayList<Long>();
        temperatureConfigList.add(minTemperature);
        temperatureConfigList.add(maxTemperature);

        mapConfig.put(BaseEnvironmentData.EnvironmentData.TEMPERATURE,temperatureConfigList);
    }

    @Override
    public Map<BaseEnvironmentData.EnvironmentData, List<Long>> getMapConfig() {
        return mapConfig;
    }

    @Override
    public List<Long> getListConfigByType(BaseEnvironmentData.EnvironmentData type) {
        return mapConfig.get(type);
    }
}
